package gui;

import java.sql.SQLException;

import gestionBDD.requetesTirage;
import interne.* ;
import com.trolltech.qt.gui.*;


public class fenetreAjoutTirage extends QWidget {
	
    private QLineEdit libelleLineEdit ;
    private QLineEdit prixLineEdit ;

	public fenetreAjoutTirage() {
		        
		/** Chemin's GroupBox' **/
        QGroupBox tirageGroup = new QGroupBox(tr("Tirage"));
        
        /* Chemin Line Edit with Label */
        QLabel libelleLabel = new QLabel(tr("Libelle {Photo|Album} :"));
        libelleLineEdit = new QLineEdit();
        libelleLineEdit.setFocus();

        /* Chemin Line Edit with Label */
        QLabel prixLabel = new QLabel(tr("Prix unitaire :"));
        prixLineEdit = new QLineEdit();
        
        /* Ok Button Box */
        QDialogButtonBox boutonOk = new QDialogButtonBox();
        boutonOk.addButton(QDialogButtonBox.StandardButton.Ok);
        boutonOk.clicked.connect(this, "ajouterTirage()");
        
        /* Chemin's Layout */
        QGridLayout tirageLayout = new QGridLayout();
        tirageLayout.addWidget(libelleLabel, 0, 0);
        tirageLayout.addWidget(libelleLineEdit, 0, 1);
        tirageLayout.addWidget(prixLabel, 1, 0) ;
        tirageLayout.addWidget(prixLineEdit, 1, 1) ;
        tirageLayout.addWidget(boutonOk, 2, 1) ;
        
        tirageGroup.setLayout(tirageLayout);
        
        setWindowTitle(tr("Nouveau Tirage"));
        setLayout(tirageLayout);
	}
	
	public void ajouterTirage() throws SQLException {
		try {
			Tirage t = new Tirage(libelleLineEdit.text(), Float.parseFloat(prixLineEdit.text())) ;
			requetesTirage.ajouterTirage(t) ;
			this.hide();
    	}
		catch(SQLException e) {
			System.out.println(e);
		}
	}
	
}
